﻿namespace BM.Tools.WebControls.MForm.Generator
{
    using System.Xml.Schema;

    /// <summary>
    /// A class representing the data of the <see cref="XmlSchemaElement"/> which is substituted.
    /// </summary>
    public class FormSubstitution : FormItem<XmlSchemaElement>
    {
        private string qualifiedName;

        /// <summary>
        /// Initializes a new instance of the <see cref="FormSubstitution"/> class.
        /// </summary>
        /// <param name="builder">
        /// The builder.
        /// </param>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="schemaObject">
        /// The schema object.
        /// </param>
        public FormSubstitution(FormBuilder builder, FormVisited parent, XmlSchemaElement schemaObject) : base(builder, parent, schemaObject)
        {
        }

        /// <summary>
        /// Gets the string representation of the qualified name.
        /// </summary>
        public override string QualifiedName
        {
            get
            {
                if (qualifiedName == null)
                {
                    var creator = new QualifiedNameTextCreator(SchemaObject.QualifiedName, Builder);
                    qualifiedName = creator.QualifiedNameText;
                }

                return qualifiedName;                
            }
        }

        /// <summary>
        /// Gets schema element max occurs.
        /// </summary>
        protected override decimal SchemaObjectMaxOccurs
        {
            get
            {
                return SchemaObject.MaxOccurs;
            }
        }

        /// <summary>
        /// Gets schema element min occurs.
        /// </summary>
        protected override decimal SchemaObjectMinOccurs
        {
            get
            {
                return SchemaObject.MinOccurs;
            }
        }
    }
}
